//
//  ZBAlertViewBase.m
//  YouHui
//
//  Created by  on 11-12-13.
//  Copyright (c) 2011年 netease. All rights reserved.
//

#import "ZBAlertViewBase.h"

@implementation ZBAlertViewBase

@synthesize titleLabel=_titleLabel;
@synthesize titleIcon=_titleIcon;
@synthesize sepColor=_sepColor;
@synthesize buttons=_buttons;

-(void)buttonPressed:(id)sender {
    [self dismissWithButtonIndex:[_buttons indexOfObject:sender]];
}

-(id)initWithTitle:(NSString*)title delegate:(id)delegate button:(NSString*)buttonTitle otherButtons:(va_list)otherButtonTitles
{
    self = [super init];
    if (self) {
        self.delegate = delegate;
        _buttons =[[NSMutableArray alloc] initWithCapacity:3];

        NSString *otherButtonTitle= nil;
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:buttonTitle forState:UIControlStateNormal];
        button.frame = CGRectMake(0, 0, 80, 30);
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [_buttons addObject:button];
        
        do  {
            otherButtonTitle = va_arg(otherButtonTitles,id);
            if (otherButtonTitle) {
                button = [UIButton buttonWithType:UIButtonTypeCustom];
                [button setTitle:otherButtonTitle forState:UIControlStateNormal];
                button.frame = CGRectMake(0, 0, 80, 30);
                [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
                [_buttons addObject:button];  
            }
        } while (otherButtonTitle!=nil);
        
        
        _titleLabel =[[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.backgroundColor =[UIColor clearColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
        _titleLabel.text = title;
        
       
        _titleIcon =[[UIImageView alloc] initWithFrame:CGRectZero];        
    }
    return self;
}

-(void)dealloc {
    [_titleIcon release];
    [_titleLabel release];
    [_buttons release];
    [super dealloc];
}


- (void)setButtonBackgroundImage:(UIImage *)image forState:(UIControlState)state {
    for (UIButton *button in _buttons) {
        [button setBackgroundImage:image forState:state];
    }
}

@end

